package com.shixun.milktea.controller;

import com.shixun.milktea.entity.Address;
import com.shixun.milktea.service.AddressService;
import com.shixun.milktea.vo.AddressVo;
import com.shixun.milktea.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : hzc
 * @date: 2022/7/1 - 07 - 01 - 19:14
 * @Description: com.shixun.milktea.controller
 * @version: 1.0
 */
@RestController
@RequestMapping("/address")
@Api(tags = "收货地址相关接口")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping("/addOneAddress")
    @ApiOperation(value = "添加收货地址")
    public ResultVO addOneAddress(@RequestBody Address address){
        return new ResultVO(addressService.addOneAddress(address));
    }

    @GetMapping("/getAddressByConsumerId/{consumerId}")
    @ApiOperation(value = "获取所有收货地址")
    public ResultVO getAddressByConsumerId(@PathVariable("consumerId") Integer consumerId){
        return new ResultVO(addressService.getAddressByConsumerId(consumerId));
    }

    @PutMapping("/updateOneAddress")
    @ApiOperation(value = "修改收货地址")
    public ResultVO updateOneAddress(@RequestBody Address address){
        return new ResultVO(addressService.updateOneAddress(address));
    }

    @DeleteMapping("/updateOneAddress/{addressId}")
    @ApiOperation(value = "删除收货地址")
    public ResultVO updateOneAddress(@PathVariable("addressId")Integer addressId){
        return new ResultVO(addressService.deleteAddressByAddressId(addressId));
    }
}
